$(function() {
	var http_url = serveUrl(); // api地址
	var subId = zcGetLocationParm('id');
	var isApp=ifApp();
	var screeWidth=document.body.offsetWidth;
	var shareThm='';
	var subName='';
	var subTypeObj = {3:1,2:2,5:5,7:4,8:3};
	var shareObj={
		imgUrl:'',
		desc:'棠果旅居活动专题',
		title:'棠果旅居',
		link: window.location.href,//不传默认当前页面@zc20170930test
	};
	var renderFnObj = {
		'banner':zcBannerFn,
		'sgl'   :zcSglFn,
		'ads'   :zcAdsFn,
		'nav'   :zcNavFn
	};
	var uid=zcGetAndSetUid();

	var initFn = function() {
		headShow();
		clearHash();
		bindEvt();
		getPageInfo();
		solveIosHead('$'); // ios 导航下移20px
		wxHandle();
	};

	var bindEvt = function() {
		$('#wrap').on('click','.tab_two li',onTabHeaderClk);
		$('#wrap').on('click','.dh',onDhClk);
		$('#wrap').on('click','.pagenav li',onPageNavClk);
		$('#wrap').on('click','.zc_sgl_pdt',onZcSglPdtClk);//单品点击
		$('#wrap').on('click','.swiper-slide',onZcBannerClk);//banner点击
		// $('#wrap').on('click','.hot_area',onHotAreaClk);//热区点击
		$('#wrap').on('click','.evy_hot',onEvyHotClk);//热区点击
	};

	var renderGift = function(success,fail,id) {
		var url=http_url+'/api/coupon/getAppointCoupon';
		var data={
			uid:uid,
			getType:1,
			id:id
		};
		$.ajax({
			url:url,
			data:JSON.stringify(data),
			type:'POST',
			contentType:'application/json;charset=UTF-8',
			success:function(res) {
				console.log(res);
				if(res.code==0) {
					$('.gift_tip').addClass('show_out').html(success);
				}else {
					$('.gift_tip').addClass('show_out').html(fail);
				}
				setTimeout(function(){
					$('.gift_tip').removeClass('show_out')
				},2000);
			},
			error:function(xhr) {
				console.log('ajax error');
			}
		})
	};

	var onEvyHotClk = function() {
		var appUrl=window.location.href;
		var type=$(this).attr('data-type');
		var travellinktype=$(this).attr('data-travellinktype');
		var linkId = $(this).attr('data-linktype');
		var datacheck = $(this).attr('data-datacheck');
		var giftsuccess = $(this).attr('data-giftsuccess');
		var giftFail = $(this).attr('data-giftFail');
		var cityCode=$(this).attr('data-code');
		var cityName=$(this).attr('data-cityName');
		var isOversea=$(this).attr('data-isOversea');
		var longitude=$(this).attr('data-longitude');
		var latitude=$(this).attr('data-latitude');
		var obj={};
		_czc.push(﻿["_trackEvent",datacheck,'点击了热区','点击的热区—id:'+(linkId||'点击类型没有id')+'']);
		if(!isApp) {
			if(type=='0') {//H5链接
				window.location.href=linkId;
			}else if(type=='1') { //礼券TODO
				if(uid) {
					renderGift(giftsuccess,giftFail,linkId);
				}else {
					window.location.href='./login/index.html?id='+subId+'';
				}
				
			}else if(type=='2') {//民宿产品详情
				// window.location.href='http://www.xywykj.com/';//下载app
				// return;
				window.location.href='http://wxzf.tgljweb.com/pages/detail/particulars.html?houseId='+linkId+'';
			}else if(type=='3') {//酒店详情
				window.location.href='http://www.xywykj.com/';//下载app
				return;
			}else if(type=='4') {//旅游详情
				// window.location.href='http://www.xywykj.com/';//下载app 170906暂无web端完整旅行业务
				// return;
				if(travellinktype==2) {//活动
					window.location.href='http://lvcheng.tgljweb.com/active-topic/activitydetail?activity_id='+linkId+'';
				}else if(travellinktype==3) {//主题线路
					window.location.href='http://lvcheng.tgljweb.com/active-topic/higodetail?higo_id='+linkId+'';
				}else if(travellinktype==5) { //线上暂无该产品20170829
					window.location.href='http://www.xywykj.com/';//下载app
				}else if(travellinktype==7) {//印象随笔
					window.location.href='http://www.xywykj.com/';//下载app
				}else if(travellinktype==8) {
					window.location.href='http://www.xywykj.com/';//下载app
				}else {
					alert('travellinktype:'+travellinktype);
				}
			}else if(type=='5') {//民宿列表
				window.location.href='http://wxzf.tgljweb.com/pages/detail/detail.html?city='+cityCode+'&city_name='+cityName+'';//citycode待定
			}else if(type=='6') {//酒店列表
				window.location.href='http://www.xywykj.com/';//下载app
				return;
			}else if(type=='7') {//旅行列表需要citycode
				window.location.href='http://www.xywykj.com/';//下载app
				return;
				window.location.href='http://javaapi.tgljweb.com:9090/api/templates/travel/content/pages/theme_line.html?city_code='+cityCode+'';
			}
		}else {//app环境下
			if(type=='0') {
				window.location.href=linkId;
				return;
			}else if(type=='1'){//礼券
				if(uid) {
					renderGift(giftsuccess,giftFail,linkId);
				}else {
					// $('.h_top').css('backgroundColor','red');
					applyAppLogin(appUrl);
				}
			}else if(type=='2') { //民宿详情
				obj.type=1;
				obj.turnData = {tid:linkId};
			}else if(type==3) {//酒店产品详情
				obj.type=2;
				obj.turnData = {tid:linkId};
			}else if(type==4) {//旅游产品详情
				obj.type=3;
				obj.subType=subTypeObj[travellinktype];
				obj.turnData={tid:linkId};
			}else if(type==5) {//民宿列表
				obj.type=4;
				obj.turnData={
					cityName:cityName,
					cityCode:cityCode,
					isOversea:isOversea,
					longitude:longitude,
					latitude:latitude
				};
			}else if(type==6) {//酒店列表
				obj.type=5;
				obj.turnData={
					cityName:cityName,
					cityCode:cityCode
				};
			}else if(type==7) {//旅游列表（暂无web版）
				obj.type=6;
				obj.turnData = {cityCode:cityCode};
				obj.subType=1;
			}
			applyAppActivityTemplate(obj);
		}
	};

	var onZcSglPdtClk = function() {
		var parType=$(this).attr('data-partype');
		var childType=$(this).attr('data-chitype');
		var id=$(this).attr('data-id');
		var dataCheck=$(this).parents('.con_item_box').siblings('ul').find('li.current').attr('data-check');
		var obj={};
		_czc.push(﻿["_trackEvent",dataCheck,'单品点击','点击的单品—id:'+id+'']);
		if(!isApp) {
			if(parType==1) {//民宿详情
				// window.location.href='http://www.xywykj.com/';//下载app
				// return;
				window.location.href='http://wxzf.tgljweb.com/pages/detail/particulars.html?houseId='+id+'';
			}else if(parType==2) {//酒店详情
				// alert('暂无酒店H5')
				window.location.href='http://www.xywykj.com/';//下载app
				return;
			}else if(parType==3) {//旅行详情
				// window.location.href='http://www.xywykj.com/';//下载app
				// return;
				if(childType==2) {//活动
					window.location.href='http://lvcheng.tgljweb.com/active-topic/activitydetail?activity_id='+id+'';
				}else if(childType==3) {//主题线路
					window.location.href='http://lvcheng.tgljweb.com/active-topic/higodetail?higo_id='+id+'';
				}else if(childType==5) { //线上暂无该产品20170829
					window.location.href='http://www.xywykj.com/';//下载app
				}else if(childType==7) {//印象随笔
					window.location.href='http://www.xywykj.com/';//下载app
				}else if(childType==8) {
					window.location.href='http://www.xywykj.com/';//下载app
				}else {
					alert('childType:'+childType);
				}
			}
		}else {//app环境下
			obj.type=parType;
			// obj.tid=id;
			obj.turnData={
				tid:id
			};
			if(parType==3) {
				obj.subType=subTypeObj[childType];
			}
			console.log(obj);
			applyAppActivityTemplate(obj);
		}
	};

	var renderTypeJump = function(jumpType,jumpTypeChild,cityCode,id,cityName,isOversea,isOversea,latitude,longitude,dataCheck) {
		var obj={};
		_czc.push(﻿["_trackEvent",dataCheck,'点击banner图','点击的banner—id:'+id+'']);
		if(!isApp) { //浏览器环境下,暂只支持此情况TODO
			if(jumpType==1) { //H5链接
				window.location.href=jumpTypeChild;
			}else if(jumpType==2) { //民宿产品详情
				// window.location.href='http://www.xywykj.com/';//下载app
				// return;
				window.location.href='http://wxzf.tgljweb.com/pages/detail/particulars.html?houseId='+jumpTypeChild+'';
			}else if(jumpType==3) {//酒店产品详情
				// alert('酒店H5暂无');
				window.location.href='http://www.xywykj.com/';//下载app
				return;
			}else if(jumpType==4) {//旅游产品详情（暂无web可支付版）
				// window.location.href='http://www.xywykj.com/';//下载app
				// return;
				if(jumpTypeChild==2) {//活动
					window.location.href='http://lvcheng.tgljweb.com/active-topic/activitydetail?activity_id='+id+'';
				}else if(jumpTypeChild==3) {//主题线路
					window.location.href='http://lvcheng.tgljweb.com/active-topic/higodetail?higo_id='+id+'';
				}else if(jumpTypeChild==5) { //线上暂无该产品20170829
					window.location.href='http://www.xywykj.com/';//下载app
				}else if(jumpTypeChild==7) {//印象随笔
					window.location.href='http://www.xywykj.com/';//下载app
				}else if(jumpTypeChild==8) {
					window.location.href='http://www.xywykj.com/';//下载app
				}else {
					alert('jumpTypeChild:'+jumpTypeChild);
				}
			}else if(jumpType==5) {//民宿列表
				window.location.href='http://wxzf.tgljweb.com/pages/detail/detail.html?city='+cityCode+'&city_name='+cityName+'';
			}else if(jumpType==6) {//酒店列表

			}else if(jumpType==7) {//旅游列表（暂无web可支付版,主题线路默认）
				window.location.href='http://javaapi.tgljweb.com:9090/api/templates/travel/content/pages/theme_line.html?city_code='+cityCode+'';
			}
		}else { //app环境下
			if(jumpType==1) { //H5链接
				window.location.href=jumpTypeChild;
				return;
			}else if(jumpType==2) { //民宿产品详情
				obj.type=1;
				obj.turnData = {tid:id};
			}else if(jumpType==3) {//酒店产品详情
				obj.type=2;
				obj.turnData = {tid:id};
			}else if(jumpType==4) {//旅游产品详情（暂无web版,不能支付）
				obj.type=3;
				obj.subType=subTypeObj[jumpTypeChild];
				obj.turnData={tid:id};
			}else if(jumpType==5) {//民宿列表
				obj.type=4;
				obj.turnData={
					cityName:cityName,
					cityCode:cityCode,
					isOversea:isOversea,
					longitude:longitude,
					latitude:latitude
				};

			}else if(jumpType==6) {//酒店列表
				obj.type=5;
				obj.turnData={
					cityName:cityName,
					cityCode:cityCode
				};
			}else if(jumpType==7) {//旅游列表（暂无web版）
				obj.type=6;
				obj.turnData = {cityCode:cityCode};
				obj.subType=1;//默认成主题线路TODO
			}
			applyAppActivityTemplate(obj);
		}
	};

	var onZcBannerClk =function() {
		var jumpType=$(this).attr('data-partype');
		var jumpTypeChild=$(this).attr('data-chitype');
		var cityCode=$(this).attr('data-code');
		var id=$(this).attr('data-id');
		var cityName=$(this).attr('data-cityName');
		var isOversea=$(this).attr('data-isOversea');
		var longitude=$(this).attr('data-longitude');
		var latitude=$(this).attr('data-latitude');
		var dataCheck=$(this).attr('data-check');
		renderTypeJump(jumpType,jumpTypeChild,cityCode,id,cityName,isOversea,isOversea,latitude,longitude,dataCheck);
	};

	var clearHash = function() {
		if (window.location.hash != "") {
	    	window.location.hash = "";
		}	
	};

	var onPageNavClk = function() {
		$(this).addClass('find_nav_cur').siblings('.find_nav_cur').removeClass('find_nav_cur');
	};

	var onTabHeaderClk = function() {
		var index = $(this).index();
		var $cnts = $(this).parents('.content_box').find('.con_item_box>div');
		$(this).addClass('current').siblings('.current').removeClass('current');
		$cnts.eq(index).css('display','block').siblings().css('display','none');

	};

	var onDhClk = function() {
		// $('body').css('backgroundColor','red');
		// $('.slide_tab_box ul').slideToggle();
		$('.slide_tab_box ul').toggle(268);
	};



	var getPageInfo = function() {
		var url = http_url+'/api/subject/getSubject'; // 接口地址
		var ajax_str = JSON.stringify({subjectId:subId});
		if(!subId) {
			alert('id缺省TODO');
			return;
		};
		console.log(new Date());
		$.ajax({
			url:url,
			data:ajax_str,
			type:'POST',
			contentType:'application/json;charset=UTF-8',
			success:function(res) {
				// console.log(new Date());
				// console.log(res);
				if(res.data.subject.enabled==2) { //禁用状态 （0921添加）
					$('#no_activity').addClass('show_out');
					$('.theme_share').remove();//app环境下去掉分享按钮
					return;
				}else {
					$('#no_activity').remove();
				}
				renderPageManFn(res.data.dataList);
				renderPageAllFn(res.data.subject);
			},
			error:function(xhr) {
				console.log(xhr);
				console.log('ajax error');
			}
		})
	};

	var renderPageAllFn = function(obj) {
		if(obj.goTop=='0') {
			showGotoTop();
		}
		shareObj.title = shareThm= document.title= obj.subShare;
		shareObj.desc = subName= obj.subName;
		console.log(shareObj);
		$('body').css({'backgroundColor':obj.bgColor,color:obj.wordColor});
	};

	var renderPageManFn = function(arr) { //渲染datalist
		var $swiperDom=null;
		var $firstDiv=null;
		var $navDiv=null;
		$.each(arr, function(i, obj) {
			$('#wrap').append(renderFnObj[obj.type](obj));
		});
		shareObj.imgUrl=$('#wrap img:first').attr('src');
		console.log(shareObj);
		$swiperDom=$('.swiper-container');
		$firstDiv=$('#wrap>div:nth-child(1)');
		$navDiv=$('#wrap>div.wrap_tab');
		$firstDiv.after($navDiv);
		$.each($swiperDom, function(index, val) {
			creatSwiper(val);
		});

		
	};

	var showGotoTop = function() {
		$(window).on('scroll',function() {
			var t=$('body').scrollTop();
			var h = window.screen.height;
			// console.log(1221);
			if(t>h) {
				$('.gotop').css('display','block');
			}else {
				$('.gotop').css('display','none');
			}
		})
		
		$('.gotop').on('click',function() {
			$("body").scrollTop(0);
		})
	};

	var headShow = function() {
		if(isApp) {
			$('#pt_wp').addClass('show_out');
			$(document).on('scroll',onWinScroll);
			$('.goback').on('click',function() {
				applyAppDetailGoback();
			});
			$('.theme_share').on('click',function() {
				// applyAppShare(obj);
				var shareObj={};
				shareObj['shareImgUrl']  = $('img').eq(0).attr('src'); // 分享图片 默认取第一张图
				shareObj['shareUrl'   ]  = window.location.href+"&tgshare=true"; //分享url
				shareObj['shareTitle' ]  = shareThm;
				shareObj['shareContent'] = subName;    
				applyAppShare(   JSON.stringify(shareObj)  );
			});
		}else {
			$('#pt_wp').remove();
		}
	};	

	var onWinScroll = function(){
	 	var h = $('#pt_wp').height();
    	if($("body").scrollTop()>=h){
            $('.h_top').addClass('show_bg');
            $('.goback').css('backgroundImage','url(img/go_back_white.png)');
            $('.theme_share').css('backgroundImage','url(img/share_white.png)');
            // $(".gotop").show();
            // $(".slide_tab_box>ul").css("bottom",'5.75rem');
		}else{
          	$('.h_top').removeClass('show_bg');
            $('.goback').css('backgroundImage','url(img/go_back_white.png)');
            $('.theme_share').css('backgroundImage','url(img/share_white.png)');
            // $(".gotop").hide();
            // $(".slide_tab_box>ul").css("bottom",'3rem');
		}
    };

	function zcBannerFn(obj) {
		var str = '';
		str+=
			'<div class="swiper-container" id='+obj.anchorLocaltion+'>'+
				'<div class="swiper-wrapper">'+
					renderBannerSilder(obj.sliders)+
				'</div>'+
				'<div class="swiper-pagination"></div>'+
			'</div>'
		return str;
	}

	function renderBannerSilder(arr) {
		var str='';
		$.each(arr, function(i, obj) {
			var srcPic=obj.pic;
			var cityCode=obj.cityCode;
			str+=   '<div class=swiper-slide data-latitude='+obj.latitude+' data-longitude='+obj.longitude+' data-isOversea='+obj.isOversea+' data-cityCode='+obj.cityCode+' data-cityName='+obj.cityName+' data-check='+(obj.dataCheck||'banner')+' data-partype='+obj.linkType+' data-id='+obj.jumpLink+' data-code='+(cityCode)+' data-chitype='+(obj.travelLinkType)+'>'+
				   		'<img src='+srcPic+' >'+
			        '</div>';
		});
		return str;
	}

	function zcSglFn(obj) {
		var str='';
		var psn = obj.anchorLocaltion;
		str+=
			'<div class="content_box" id='+psn+'>'+
				'<ul class="tab_two clearfix">'+
					renderSglTab(obj.tabs)+
				'</ul>'+
				'<div class="con_item_box clearfix">'+
					renderSglCnt(obj.tabs,obj.sort)+
				'</div>'+
			'</div>'
		return str;
	}

	function renderSglCnt(arr,sort) {
		var str='';
		$.each(arr, function(i, obj) {

			str+=
				'<div class="evy_tab_cnt clearfix">'+
					renderSglPdt(obj.product,sort)+
				'</div>'
		});
		return str;
	}

	function renderSglPdt(arr,sort) {
		var str='';
		$.each(arr, function(i, obj) {
			if(sort=='narrow') {
				str+=renderPdtByNarrow(obj.productList,obj.type,obj.travelSecondType);
			}else {
				str+=renderPdtByWidth(obj.productList,obj.type,obj.travelSecondType);
			}
		});
		return str;
	}

	function renderPdtByWidth(arr,parType,chiType) {
		var str = '';
		$.each(arr, function(i, obj) {
			var currDesc=(obj.imgDesc)?(obj.imgDesc.slice(0,25)):' ';
			str+=
				'<div class="item item_h zc_sgl_pdt" data-partype='+parType+' data-chitype='+chiType+' data-id='+obj.productId+'>'+
					'<img src='+obj.coverImg+'>'+
					'<div class="item_h_des clearfix">'+
						'<p class="word fl">'+currDesc+'</p>'+
						renderWidthPrice(obj.price)+
					'</div>'+
				'</div>'
		});

		function renderWidthPrice(price_str) {
			if(price_str) {
				return '<p class="price fr">¥<span>'+price_str+'</span>起</p>';
			}else {
				return ' ';
			}
		}
		return str;
	}



	function renderPdtByNarrow(arr,parType,chiType) {
		var str = '';
		$.each(arr, function(i, obj) {
			str+=
				'<div class="item item_x zc_sgl_pdt" data-partype='+parType+' data-chitype='+chiType+' data-id='+obj.productId+'>'+
					'<div class="img_box po_re">'+
						'<img src='+obj.coverImg+'>'+
						renderPrice(obj.price)+
					'</div>'+
					'<p class="word">'+obj.imgDesc+'</p>'+
				'</div>'
		});

		function renderPrice(price_str) {
			if(price_str) {
				return '<p class="po_ab">¥<span>'+price_str+'起</span></p>';
			}else {
				return ' ';
			}
		}
		return str;
	}

	function renderSglTab(arr) {
		var str='';
		var len=arr.length;
		var widthP=0;
		if( arr.length==1&&(  !arr[0].tabLabel)  ) {
			return str;
		}
		if(len<=5) {
			widthP=(100/len)+'%';
		}else {
			widthP='22.2%';//可以放四个半
		}
		// if(len<=2) {
		// 	widthP='50%';
		// }else if(len==3) {
		// 	widthP='33.33%';
		// }else if(len==4) {
		// 	widthP='25%';
		// }
		$.each(arr, function(i, obj) {
			if(i==0) {
				str+='<li class="current" data-check='+(obj.dataCheck||'单品')+' style=width:'+widthP+'><span>'+obj.tabLabel+'</span></li>';
			}else {
				str+='<li  data-check='+(obj.dataCheck||'单品')+'  style=width:'+widthP+'><span>'+obj.tabLabel+'</span></li>';
			}
		});
		return str;
	}

	function zcAdsFn(obj) {
		var str='';
		var arr=obj.hotAreas;
		var k=screeWidth/parseInt(obj.imgWidth);
		// if(obj.hotType!="allPic") {
		// 	alert('暂只能全区');
		// 	return;
		// }
		str+=   
				'<div class="hot_area clearfix" id='+obj.anchorLocaltion+'>'+
			  	 	'<img src='+obj.pic+'>'+
			  	 	renderHotAreas(arr,k,obj.hotType)+
			    '</div>'
		return str;	
	}

	function renderHotAreas(arr,k,type) {
		// console.log(arr);
		var str='';
		if(type=="allPic") {
			return '<div class=evy_hot data-cityName='+(arr[0].cityName||'null')+' data-code='+(arr[0].cityCode||'0')+' data-linkType='+arr[0].linkType+' data-giftSuccess='+(arr[0].giftSuccess||'领取成功!')+'  data-dataCheck='+(arr[0].dataCheck||' dataCheck')+'  data-giftFail='+(arr[0].giftFail||'领取失败！ ')+'  data-type='+arr[0].type+'  style=top:0;left:0;width:100%;height:100%  data-travelLinkType='+(arr[0].travelLinkType||'3')+'></div>'
		}
		if(type=="noHot") {
			// console.log('无热区，纯图片展示');
			return str;
		}
		$.each(arr, function(i, obj) {
			str+=
				'<div class=evy_hot  data-cityName='+(arr[0].cityName||'null')+'  data-code='+(obj.cityCode||'0')+' data-giftSuccess='+(obj.giftSuccess||' 领取成功！')+' data-travelLinkType='+(obj.travelLinkType||'3')+' data-giftFail='+(obj.giftFail||' 领取失败！')+'  data-dataCheck='+(obj.dataCheck||' dataCheck')+'  data-type='+obj.type+' data-linkType='+obj.linkType+' style=top:'+df(k,obj.areaTop)+';left:'+df(k,obj.areaLeft)+';width:'+df(k,obj.areaWidth)+';height:'+df(k,obj.areaHeight)+'></div>'
		});

		function df(k,str) {
			return( k*parseInt(str)||' ')+'px';
		}
		return str;
	}

	function zcNavFn(obj) {
		var str='';
		if(obj.navType=='aside') {
			str+=
				'<div class="slide_tab">'+
					'<div class="slide_tab_box">'+
						'<ul>'+
							renderAsideNavLi(obj.nodes)+
						'</ul>'+
					'<div class="dh">导航</div>'+
					'</div>'+
				'</div>'
		}else {
			str+=
				'<div class="wrap_tab">'+
				    '<div class="find_nav_list">'+
			            '<ul class="pagenav">'+
			            	renderNavLi(obj.nodes)+
			            '</ul>'+
				   ' </div>'+
				'</div>'
		}
		return str;
	}

	function renderAsideNavLi(arr) {
		var str='';
		$.each(arr, function(i, obj) {

			if(i==0) {
				str+='<li class=""><a href=#'+obj.anchorLocaltion+'>'+obj.name+'</a></li>';
			}else {
				str+='<li><a href=#'+obj.anchorLocaltion+'>'+obj.name+'</a></li>';
			}
		});
		return str;
	}

	function renderNavLi(arr) {
		var str='';
		$.each(arr, function(i, obj) {

			if(i==0) {
				str+='<li class="find_nav_cur"><a href='+obj.anchorLocaltion+'>'+obj.name+'</a></li>';
			}else {
				str+='<li><a href=#'+obj.anchorLocaltion+'>'+obj.name+'</a></li>';
			} 
		});
		return str;
	}

	function creatSwiper(dom) { //接收class||dom创建swiper
		new Swiper(dom,{
			pagination : '.swiper-pagination',
			paginationType : 'bullets',
			observer:true,
			observeParents:true,
			autoplay : 6000,
			loop:true
		})
	}

	function ifApp () {
		var nu = navigator.userAgent;
		var boole=nu.indexOf('tgljAppShow')>0;
		return boole;
	}

	function wxHandle() {
		var nu = navigator.userAgent;
		if(nu.match(/MicroMessenger/i)=="micromessenger") {  
	       !function() {
                $.ajax({
                    type:'POST',
                    url:'http://javaapi.tgljweb.com:9090/api/unionpay/getwxinitconfig',
                    data:JSON.stringify({url: window.location.href.split("#")[0]}),
                    contentType:'application/json;charset=UTF-8',
                    success:function(res) {
                        var data=res.data;
                        wx.config({
                            debug: false,
                            appId: data.appid,
                            timestamp:data.timestamp,
                            nonceStr: data.noncestr, 
                            signature: data.signature,
                            jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ','MenuShareWeibo','onMenuShareQZone']
                        });
                    },
                    error:function(xhr) {
                        console.log(xhr);
                    }
                })
            }();
            wx.ready(function() {
		    	wx.onMenuShareTimeline(shareObj);
		    	wx.onMenuShareAppMessage(shareObj);
		    	wx.onMenuShareQQ(shareObj);
		    	wx.MenuShareWeibo(shareObj);
		    	wx.onMenuShareQZone(shareObj);
		    });
	    }
	}
	

	initFn();
})
